<?php
    /**
    * Edit Real Estate Project
    * @author trungdt
    * @since June 23, 2011
    * 
    * Change logs
    * 
    */

    if (!defined('EXPONENT')) exit('');

    $project = null;
    $config=null;
    if (isset($_GET['id'])) {
        $project = $db->selectObject('duan','id='.intval($_GET['id']));
        if ($project) {
            $loc = unserialize($project->location_data);
        }
    }
    
    $config = $db->selectObject('duanmodule_config',"location_data='".serialize($loc)."'");

    if ($config == null) {
        $config->image_col=0;
    }
    
    if (exponent_permissions_check('administrate',$loc) || ($project && exponent_permissions_check('edit',$loc)) || (!$project && exponent_permissions_check('create',$loc))) {
        $form = duan_duan::form($project,$config, $loc);
        $form->location($loc);
        $form->meta('action','save');

        $template = new template('duanmodule','_form_edit');
        $template->assign('is_edit',(isset($project->id)? 1 : 0));
        $template->assign('form_html',$form->toHTML());
        $template->output();
    } else {
        echo SITE_404_HTML;
    }

?>